<!DOCTYPE HTML>
<html>
<head>
    <title>Error</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/stylesheets/formdata.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <script src="/scripts/miniui/miniui.js"></script>
    <script src="/qiniuJs/goodsFormdata.js"></script>
    <script>
        var domain = "<%= domain %>"; // you bucket domain  eg: http://xxx.bkt.clouddn.com
    </script>
</head>
<body>
<div class="container">
    <!-- Document：https://developer.qiniu.com/kodo/manual/form-upload -->
    <form id="testform" method="post" enctype="multipart/form-data">
        <input name="key" id="key" type="hidden" value="">
        <input name="token" type="hidden" value="<%= uptoken %>">
        <input id="userfile" name="file" type="file"/>
        <!-- take photo with phone -->
        <!-- <input id="userfile" name="file" accept="image/*" type="file" /> -->
        <!-- take video with phone -->
        <!-- <input id="userfile" name="file" type="file" accept="video/*"/> -->
        <input name="accept" type="hidden"/>
    </form>
    <!-- add file -->
    <label for="userfile">
        <span></span>
        <em>添加商品图片注意图片顺序第一张是封面图</em>
    </label>

    <!-- upload info -->
    <div class="selected-file"></div>
    <div class="progress"></div>
    <div class="uploaded-result"></div>
</div>
<div style="padding-left: 60px">
    <div id="form1">
        <span style="width:80px;display:inline-block;">商品昵称：</span>
        <input id="title" class="mini-textbox" style="width:155px;"/>

        <span style="width:80px;display:inline-block;margin-left: 30px">库存：</span>
        <input id="stock" class="mini-textbox" vtype="float" style="width:155px;" value="9999"/>
        <br/><br/>

        <span style="width:80px;display:inline-block;">商品状态：</span>
        <input id="status" class="mini-combobox" style="width:155px;" data="shopStatus" value="1"/>

        <span style="width:80px;display:inline-block;margin-left: 30px">能否团购：</span>
        <input id="groupBuying" class="mini-combobox" field="id" style="width:155px;" data="groupBuying"/>

        <br/><br/>

        <span style="width:80px;display:inline-block;">是否包邮：</span>
        <input id="freePost" class="mini-combobox" style="width:155px;" data="freePost" value="1"/>


        <span style="width:80px;display:inline-block;margin-left: 30px">团购价格：</span>
        <input id="groupPrice" class="mini-textbox" style="width:155px;" vtype="float"/>

        <br/><br/>

        <span style="width:80px;display:inline-block;">销量：</span>
        <input id="saleNums" class="mini-textbox" style="width:155px;" vtype="int"/>

        <span style="width:80px;display:inline-block;margin-left: 30px">原价：</span>
        <input id="originalPrice" class="mini-textbox" style="width:155px;" vtype="float" required="true"/>

        <br/><br/>
        <span style="width:80px;display:inline-block;">价格：</span>
        <input id="price" class="mini-textbox" onvaluechanged="setDiscount()" style="width:155px;" vtype="float"
               required="true"/>

        <span style="width:80px;display:inline-block;margin-left: 30px">能否订制：</span>
        <input id="customize" class="mini-combobox" style="width:155px;" data="customize" value="1"/>

        <br/><br/>
        <span style="width:80px;display:inline-block;">商品折扣：</span>
        <input id="discount" class="mini-textbox" onvaluechanged="setPrice()" style="width:155px;" vtype="range:0,10"
               required="true"/>

        <span style="width:80px;display:inline-block;margin-left: 30px">店铺：</span>
        <input id="shopOId" class="mini-buttonedit" onbuttonclick="onButtonEdit" name="a" textName="b" value="5b446f5a67f356003a7c7f69" text="锡恩官方店"
               style="width: 155px"/>
        <br/><br/>

        <span style="width:80px;display:inline-block;">推广佣金：</span>
        <input id="promotePrice" class="mini-textbox" vtype="float" onvaluechanged="setPromotionPrice()"
               required="true" style="width:155px;" value="0"/>

        <span style="width:80px;display:inline-block;margin-left: 30px">商品分类：</span>
        <input id="goodsType" class="mini-combobox" valueField="objectId" style="width: 155px" data="goodsTypesList" required="true"/>
        <br/><br/>

        <span style="width:80px;display:inline-block;">商品描述：</span>
        <textarea id="describe" class="mini-textarea" style="width: 450px;height: 100px"></textarea>

        <br/><br/>
        <input id="sellerOId" class="mini-textbox" style="display: none" value="5b446c419f54540031397e5e"/>
        <input id="downUrl" class="mini-textbox" style="display: none"/>
    </div>
    <div style="width:570px;">
        <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="icon-add" onclick="addRow()" plain="true" tooltip="增加...">增加</a>
                        <a class="mini-button" iconCls="icon-remove" onclick="removeRow()" plain="true">删除</a>
                        <span class="separator"></span>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div id="datagrid1" class="mini-datagrid" style="width:570px;height:280px;"
         idField="id"
         allowResize="true" pageSize="20"
         allowCellEdit="true" allowCellSelect="true" multiSelect="true"
         editNextOnEnterKey="true" editNextRowCell="true"

    >
        <div property="columns">
            <div type="indexcolumn"></div>
            <div type="checkcolumn"></div>
            <div name="model" field="model" headerAlign="center"  width="150">商品型号
                <input property="editor" class="mini-textbox" style="width:100%;" minWidth="100"/>
            </div>
            <div name="stock" field="stock" width="100" >商品库存
                <input property="editor" class="mini-spinner" minValue="0" maxValue="999999999" style="width:100%;"/>
            </div>
            <!--ComboBox：本地数据-->

            <!--ComboBox：远程数据-->
        </div>
    </div>
</div>
<div style="margin: 30px 0;text-align: center">
    <a class="mini-button " iconCls="icon-ok" onclick="updataUser()">确定</a>
    <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
</div>
</body>
<script>
    var goodsTypesList = JSON.parse('<%- goodsTypes %>');
    var shopStatus = [{ id:0 , text:'下架' }, { id: -1, text:'删除'},{id:1,text:'上架'},{id:2,text:'默认'}];
    var groupBuying = [{ id:1,text:'可以团购'},{id:0,text:'不能团购'}];
    var freePost = [{id:1,text:'包邮'},{id:0,text:'不包邮'}];
    var customize = [{id:1,text:'可以定制'},{id:-1,text:'不可以定制'}];
    mini.parse();
    var grid = mini.get("datagrid1");
    function updataUser() {
        var data = grid.getChanges();
        var model = mini.encode(data);

        var shopOId = mini.get("shopOId").getValue();
        var title = mini.get("title").getValue();
        var promotePrice = mini.get("promotePrice").getValue();
        var status = mini.get("status").getValue();
        var groupBuying = Number(mini.get("groupBuying").getValue());
        var freePost = mini.get("freePost").getValue();
        var groupPrice = mini.get("groupPrice").getValue();
        var saleNums = mini.get("saleNums").getValue();
        var originalPrice = mini.get("originalPrice").getValue();
        var price = mini.get("price").getValue();
        var customize = mini.get("customize").getValue();
        var discount = mini.get("discount").getValue();
        var describe = mini.get("describe").getValue();
        var stock = mini.get("stock").getValue();
        var sellerOId = mini.get("sellerOId").getValue();
        var downUrl = mini.get("downUrl").getValue();
        var goodsTypeOId = mini.get("goodsType").getValue();
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) {
            alert("请正确填写数据")
            return
        };

        $.ajax({
            type: "POST",
            url: "/getdata/updataGoods",
            data: {
                shopOId:shopOId,
                title: title,
                promotePrice: promotePrice,
                status: status,
                groupBuying: groupBuying,
                freePost: freePost,
                groupPrice: groupPrice,
                saleNums: saleNums,
                originalPrice: originalPrice,
                price: price,
                customize: customize,
                discount: discount,
                describe: describe,
                sellerOId: sellerOId,
                model: model,
                downUrl: downUrl,
                stock: stock,
                goodsTypeOId:goodsTypeOId
            },
            success: function (result) {
                if (result=='1') {
                    CloseWindow("save");
                }else{
                    alert("请填写正确数据");
                }
            }
        })

    }
    //    关闭窗口
    function CloseWindow(action) {
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }
    function onOk(e) {
        SaveData();
    }
    function onCancel(e) {
        CloseWindow("cancel");
    }
    function setPrice() {
        var price = mini.get("price");
        var discount = mini.get("discount").getValue();
        var originalPrice = mini.get("originalPrice").getValue();
        var priceValue = (originalPrice*discount/10);
        price.setValue(priceValue);
    }
    function setDiscount() {
        var discount = mini.get("discount");
        var price = mini.get("price").getValue();
        var originalPrice = mini.get("originalPrice").getValue();
        var discountValue = (price/originalPrice*10).toFixed(1);
        discount.setValue(discountValue);
    }
    function onButtonEdit(e) {
        var btnEdit = this;
        var sellerOId = mini.get("sellerOId");
        mini.open({
            url: "/editor/shopList",
            title: "选择列表",
            width: 700,
            height: 450,
            ondestroy: function (action) {
                //if (action == "close") return false;
                if (action == "ok") {
                    var iframe = this.getIFrameEl();
                    var data = iframe.contentWindow.GetData();
                    data = mini.clone(data);    //必须
                    if (data) {
                        console.log(data.userOId);
                        btnEdit.setValue(data.id);
                        btnEdit.setText(data.text);
                        sellerOId.setValue(data.userOId)
                    }
                }

            }
        });

    }
    function setPromotionPrice() {
        var price = mini.get("price").getValue();
        var promotePrice = mini.get("promotePrice").getValue();
        var promotionPriceValue = mini.get("promotePrice");
        if (promotePrice>price){
            alert("推广佣金最大不能超过价格");
            promotionPriceValue.setValue(price);
        }
    }

    ///////////商品类型




    function addRow() {
        var newRow = { stock: "9999" };
        grid.addRow(newRow, 0);


        grid.beginEditCell(newRow, "LoginName");
    }
    function removeRow() {
        var rows = grid.getSelecteds();
        if (rows.length > 0) {

            grid.removeRows(rows, true);
        }
    }

</script>
</html>